﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharedGenomics.Workbench.PresentationModel
{
    public class EditUserMarkerPTO : PresentationTransferObject
    {
        public string MarkerName
        {
            get { return this.GetPropertyValue<string>("MarkerName"); }
            set { this.SetPropertyValue("MarkerName", value); }
        }

        public string RsNumber
        {
            get { return this.GetPropertyValue<string>("RsNumber"); }
            set { this.SetPropertyValue("RsNumber", value); }
        }

        public string Chromosome
        {
            get { return this.GetPropertyValue<string>("Chromosome"); }
            set { this.SetPropertyValue("Chromosome", value); }
        }

        public string Position
        {
            get { return this.GetPropertyValue<string>("Position"); }
            set { this.SetPropertyValue("Position", value); }
        }

        public bool EditingRsNumber
        {
            get { return this.GetPropertyValue<bool>("EditingRsNumber"); }
            set { this.SetPropertyValue("EditingRsNumber", value); }
        }

        protected override void Validate(SharedGenomics.Core.IValidationErrorCollection validationErrors)
        {
            if (this.EditingRsNumber)
            {
                int rsNumber;
                if (!int.TryParse(this.RsNumber, out rsNumber))
                {
                    validationErrors.Add("Invalid rs number", this, "RsNumber");
                }
            }
            else
            {
                //try to parse chromosome and position
                int chr;
                if (!SharedGenomics.Domain.Chromosome.TryParse(this.Chromosome, out chr))
                {
                    validationErrors.Add("Chromosome indexes should be in the range [1-26, X, Y, XY, MT]", this, "Chromosome");
                }

                long pos;
                if (!long.TryParse(this.Position, out pos))
                {
                    validationErrors.Add("Invalid position", this, "Position");
                }
            }
        }
    }
}
